<?php


namespace App\Repositories;


use App\Exceptions\BasicException;

class BlindDateRepository
{
    //新增或编辑牵手道具
    public function addOrEditHoldHandsProp($param)
    {
        $id = $param['id'] ?? 0;
        $propName = $param['prop_name'];
        $picture = $param['picture'];
        $special = $param['special'];
        $specialDuration = $param['special_duration'];
        $level = $param['level'];
        $score = $param['score'];

        $data = [
            'name' => $propName,
            'picture' => $picture,
            'special' => $special,
            'special_time' => $specialDuration,
            'level' => $level,
            'score' => $score,
            'update_time' => time(),
        ];

        if ($id > 0) {
            $scene = app('model_game_dating_scene_config')->select('id')->where('id', $id)->first();
            if (empty($scene)) throw new BasicException(0, '参数错误，记录不存在');

            $res = app('model_game_dating_scene_config')->where('id', $id)->update($data);

        } else {
            $data['create_time'] = time();
            $res = app('model_game_dating_scene_config')->insert($data);
        }
        return $res;
    }

    //新增或编辑cp道具
    public function addOrEditCpProp($param)
    {
        $id = $param['id'] ?? 0;
        $propName = $param['prop_name'];
        $productIdMen = $param['product_id_men'];
        $productIdWomen = $param['product_id_women'];
        $days = $param['days'];
        $level = $param['level'];
        $score = $param['score'];

        $data = [
            'name' => $propName,
            'product_id_men' => $productIdMen,
            'product_id_women' => $productIdWomen,
            'days' => $days,
            'level' => $level,
            'score' => $score,
            'update_time' => time(),
        ];

        if ($id > 0) {
            $cpProp = app('model_game_dating_cp_head_picture')->select('id')->where('id', $id)->first();
            if (empty($cpProp)) throw new BasicException(0, 'id错误，记录不存在');

            $res = app('model_game_dating_cp_head_picture')->where('id', $id)->update($data);
        } else {
            $data['create_time'] = time();
            $res = app('model_game_dating_cp_head_picture')->insert($data);
        }
        return $res;
    }

    //新增或编辑桂冠道具
    public function addOrEditLaurelProp($param)
    {
        $id = $param['id'] ?? 0;
        $picture = $param['picture'];
        $special = $param['special'];
        $sex = $param['sex'];
        $level = $param['level'];
        $score = $param['score'];

        $data = [
            'picture' => $picture,
            'special' => $special,
            'sex' => $sex,
            'level' => $level,
            'score' => $score,
            'update_time' => time(),
        ];

        if ($id > 0) {
            $laurel = app('model_game_dating_head_picture_config')->select('id')->where('id', $id)->first();
            if (empty($laurel)) throw new BasicException(0, 'id错误，记录不存在');

            $res = app('model_game_dating_head_picture_config')->where('id', $id)->update($data);
        } else {
            $data['create_time'] = time();
            $res = app('model_game_dating_head_picture_config')->insert($data);
        }
        return $res;
    }

    //新增或编辑月下老人道具
    public function addOrEditCupidProp($param)
    {
        $id = $param['id'] ?? 0;
        $picture = $param['picture'];
        $icon = $param['icon'];
        $arrow = $param['arrow'];
        $propName = $param['prop_name'];
        $level = $param['level'];
        $price = $param['price'];

        $data = [
            'name' => $propName,
            'picture' => $picture,
            'icon' => $icon,
            'arrow' => $arrow,
            'level' => $level,
            'price' => $price,
            'update_time' => time(),
        ];

        if ($id > 0) {
            $cupid = app('model_game_dating_cupid')->select('id')->where('id', $id)->first();
            if (empty($cupid)) throw new BasicException(0, 'id错误，记录不存在');

            $res = app('model_game_dating_cupid')->where('id', $id)->update($data);
        } else {
            $data['create_time'] = time();
            $res = app('model_game_dating_cupid')->insert($data);
        }
        return $res;
    }
}